<template>
<div>
  <city-header></city-header>
  <city-search :cities ="cities"></city-search>
  <city-list :cities ="cities" :hotCities="hotCities" :letter="letter"></city-list>
  <city-alphabet :cities ="cities" @change="changeAlphabet"></city-alphabet>
</div>
</template>

<script>
import cityHeader from "./components/city-header";
import citySearch from "./components/city-search";
import cityList from "./components/city-list";
import cityAlphabet from "./components/city-alphabet";
import axios from "axios";
export default {
  name: "City",
  components: {
    cityHeader,
    citySearch,
    cityList,
    cityAlphabet
  },
  data() {
    return {
      cities: {},
      hotCities: [],
      letter: "" // 字母表传过来的字母
    };
  },
  created() {
    this.getCityInfo();
  },
  methods: {
    getCityInfo() {
      axios.get("/api/city.json").then(res => {
        this.handleGetCityInfo(res);
      });
    },
    /**
    *@param {Boolean}  res.ret 这个模拟接口返回来数据。 如果为true 说明请求接口成功
     @param {Object}    res 接口返回来的数据
     */
    handleGetCityInfo(res) {
      // console.log(res);
      res = res.data;
      if (res.ret && res.data) {
        const data = res.data;
        this.cities = data.cities;
        this.hotCities = data.hotCities;
        console.log(this.hotCities);
      }
    },
    changeAlphabet(val) {
      this.letter = val;

    }
  }
};
</script>
<style lang="stylus" scoped>

</style>


